home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / pmake / bigcmdtop.mk < prev    next >
Encoding:
Text File  |  1992-05-18  |  8.5 KB  |  361 lines

  1. #
  2. # This is a library Makefile that is included by the Makefiles for
  3. # the top-level directories of multi-directory libraries ("biglib"s).
  4. # For most targets, this file just passes the targets on to each of
  5. # the subdirectories.  The file that includes this one should already
  6. # have defined the following variables:
  7. #    LIBRARY        base name of library (e.g. tcl, sx, c, etc.)
  8. #    LINTDIR        place to install lint library (we'll add a .mach
  9. #            extension here)
  10. #    SUBDIRS        subdirectories that contain "interesting" things
  11. #            (e.g., individual commands, modules of the kernel,
  12. #            of sub-portions of a large library).
  13. #    TM        target machine type for object files etc.
  14. #    TYPE        a keyword identifying which sort of command this
  15. #            is;  used to determine where to install, etc.
  16. #
  17. # A bunch of variables are passed on to lower-level makes, if they are
  18. # defined;  see the definitions immediately below for a complete list.
  19. #    
  20. # $Header: /sprite/lib/pmake/RCS/bigcmdtop.mk,v 1.38 91/11/06 18:34:52 kupfer Exp Locker: mottsmth $
  21. #
  22.  
  23. OBJS        = $(SUBDIRS:S|$|/$(TM).md/linked.o|g)
  24. POBJS        = $(SUBDIRS:S|$|/$(TM).md/linked.po|g)
  25.  
  26. #
  27. # Suffix for profiled targets.
  28. #
  29. PROFSUFFIX    ?= .pg
  30.  
  31. #
  32. # System programs -- assign conditionally so they may be redefined in
  33. # including makefile
  34. #
  35. BINDIR        ?= /sprite/cmds.$(MACHINE)
  36.  
  37. CAT        ?= $(BINDIR)/cat
  38. CP        ?= $(BINDIR)/cp
  39. MV        ?= $(BINDIR)/mv
  40. RM        ?= $(BINDIR)/rm
  41. TEST            ?= $(BINDIR)/test
  42. UPDATE        ?= $(BINDIR)/update
  43.  
  44. #
  45. # Several variables (such as where to install) are set based on the
  46. # TYPE variable.  Of course, any of these variables can be overridden
  47. # by explicit assignments.
  48. #
  49. TYPE        ?= unknown
  50. #if !empty(TYPE:Msprite)
  51. INSTALLDIR    ?= /sprite/cmds
  52. INSTALLMAN    ?= /sprite/man/cmds
  53. #elif !empty(TYPE:Mx)
  54. INSTALLDIR    ?= /X/cmds
  55. INSTALLMAN    ?= /X/man/cmds
  56. #elif !empty(TYPE:MX11R3)
  57. INSTALLDIR    ?= /mic/X11R3/cmds
  58. INSTALLMAN    ?= /mic/X11R3/man/cmds
  59. #elif !empty(TYPE:MX11R4)
  60. INSTALLDIR    ?= /X11/R4/cmds
  61. INSTALLMAN    ?= /X11/R4/man/cmds
  62. #elif !empty(TYPE:Mdaemon)
  63. INSTALLDIR    ?= /sprite/daemons
  64. INSTALLMAN    ?= /sprite/man/daemons
  65. #elif !empty(TYPE:Madmin)
  66. INSTALLDIR    ?= /sprite/admin
  67. INSTALLMAN    ?= /sprite/man/admin
  68. #elif !empty(TYPE:Mpersonal)
  69. INSTALLDIR    ?= $(HOME)/cmds
  70. INSTALLMAN    ?= $(HOME)/man/cmds
  71. LOADFLAGS    += -L$(HOME)/lib/$(TM).md
  72. XCFLAGS        += -I$(HOME)/lib/include
  73. .PATH.h        : $(HOME)/lib/include
  74. #ifndef        USERBACKUP
  75. NOBACKUP    =
  76. #endif
  77. #endif
  78. #ifdef INSTALLDIR
  79. TMINSTALLDIR    ?= $(INSTALLDIR).$(TM)
  80. #endif
  81.  
  82. #
  83. # Figure out what stuff we'll pass to sub-makes.
  84. #
  85. PASSVARS    =
  86. #ifdef        CC
  87. PASSVARS    += 'CC=$(CC)'
  88. #endif
  89. #ifdef        XCFLAGS
  90. PASSVARS    += 'XCFLAGS=$(XCFLAGS)'
  91. #endif
  92. #ifdef        XAFLAGS
  93. PASSVARS    += 'XAFLAGS=$(XAFLAGS)'
  94. #endif
  95. #ifdef        INCLUDEDIR
  96. PASSVARS    += 'INCLUDEDIR=$(INCLUDEDIR)'
  97. #endif
  98. #ifdef        INSTALLDIR
  99. PASSVARS    += 'INSTALLDIR=$(INSTALLDIR)'
  100. #endif
  101. #ifdef        TM
  102. PASSVARS    += 'TM=$(TM)'
  103. #endif
  104.  
  105. #
  106. # Collect flags and other machine-dependent things for compilation.
  107. #
  108. #include    <tm.mk>
  109. CTFLAGS        ?= -wt
  110. INSTALLFLAGS    ?=
  111. INSTALLMANFLAGS    ?=
  112. LINTFLAGS    ?= -S -m$(TM)
  113. XCFLAGS        ?=
  114. LOADFLAGS    ?=
  115. XAFLAGS        ?=
  116. CFLAGS        += -g -O $(TMCFLAGS) $(XCFLAGS)
  117.  
  118. # MAKESUBDIRS usage:
  119. #    <target> : MAKESUBDIRS
  120. #
  121. # This .USE target will simply pass <target> onto each subdirectory
  122. # in a separate make.  If the TM variable is defined, then only pass
  123. # the target on to subdirectories whose Makefiles include the given
  124. # TM among their MACHINES.
  125. #
  126. MAKESUBDIRS    : .USE .MAKE .SILENT .NOEXPORT
  127.     for i in $(SUBDIRS);
  128.     do
  129. #ifdef TM
  130.         if grep '^MACHINES' $i/Makefile | grep -s $(TM); then
  131.             true;
  132.         else continue;
  133.         fi
  134. #endif TM
  135.         echo %%% ${i} %%%
  136.         (cd $i; $(MAKE) $(PASSVARS) $(.TARGET))
  137.     done
  138.  
  139. #
  140. # MAKEINSTALL usage:
  141. #    target : source MAKEINSTALL
  142. #
  143. # The source is installed at the target and backed-up to
  144. # $(INSTALLDIR).$(TM).old
  145. #
  146. #ifndef NOBACKUP
  147. BACKUP        = -b $(INSTALLDIR).$(TM).old
  148. #ifdef BACKUPAGE
  149. BACKUP += -B $(BACKUPAGE)
  150. #endif
  151. #else
  152. BACKUP        =
  153. #endif  NOBACKUP
  154. #if !empty(TM:Mspur)
  155. # use a separate install script that doesn't strip
  156. # note that XLD has already been run
  157. MAKEINSTALL    : .USE .SILENT
  158.     $(UPDATE) -m 775 $(BACKUP) $(INSTALLFLAGS) $(.ALLSRC) $(.TARGET)
  159. #else
  160. MAKEINSTALL    : .USE .SILENT
  161.     $(UPDATE) -m 775 -s $(BACKUP) $(INSTALLFLAGS) $(.ALLSRC) $(.TARGET)
  162. #endif
  163.  
  164. #ifndef no_targets
  165. #
  166. # We should define the main targets.  See the Mkmf man page for details.
  167. #
  168.  
  169. LIBS            ?=
  170.  
  171. default            : $(TM).md/$(NAME)
  172. $(TM).md/$(NAME)    : subdirs $(LIBS) $(OBJS) -lc
  173.     $(RM) -f $(.TARGET)
  174.     $(CC) $(CFLAGS) -o $(.TARGET) $(LOADFLAGS) $(OBJS) $(LIBS)
  175. #if !empty(TM:Mspur)
  176.     $(XLD) $(.TARGET)
  177. #endif
  178.  
  179. #
  180. # make the linked.o files depend on the subdirectories so pmake won't 
  181. # stat linked.o before remaking the subdirectories and think that the top-level
  182. # target is up-to-date.  This generates N^2 dependencies, but there aren't
  183. # typically many subdirectories so this should be okay, and all the
  184. # subdirectories get remade anyway.
  185. #
  186. $(SUBDIRS:S|$|/$(TM).md/linked.o|g): $(SUBDIRS)
  187.  
  188. clean            :: .MAKE .SILENT tidy
  189.     echo "rm -f $(TM).md/$(NAME)"
  190.     rm -f $(TM).md/$(NAME)
  191.     echo "rm -f $(TM).md/$(NAME)$(PROFSUFFIX)"
  192.     rm -f $(TM).md/$(NAME)$(PROFSUFFIX)
  193.  
  194. tidy            :: .MAKE .SILENT .NOEXPORT
  195.     for i in $(SUBDIRS);
  196.     do
  197. #ifdef TM
  198.         if grep '^MACHINES' $i/Makefile | grep -s $(TM); then
  199.             true;
  200.         else continue;
  201.         fi
  202. #endif TM
  203.         echo %%% ${i} %%%
  204.         (cd $i; $(MAKE) $(PASSVARS) clean)
  205.     done
  206.  
  207. #
  208. # For "install", a couple of tricks.  First, allow local.mk to disable
  209. # by setting no_install.  Second, use :: instead of : so that local.mk
  210. # can augment install with additional stuff.  Third, don't install if
  211. # TMINSTALLDIR isn't set.
  212. #
  213. INSTCMD            = $(INSTALLDIR).$(TM)/$(NAME)
  214. #ifndef no_install
  215. #ifdef TMINSTALLDIR
  216. install            :: $(INSTCMD) installman
  217. $(INSTCMD)        : $(TM).md/$(NAME) MAKEINSTALL
  218. #else
  219. install            :: .SILENT
  220.     echo "Can't install $(NAME):  no install directory defined"
  221. #endif TMINSTALLDIR
  222. #endif no_install
  223.  
  224. #if empty(MANPAGES)
  225. installman        :: .SILENT
  226.     echo "There's no man page for $(NAME).  Please write one."
  227. #elif !empty(MANPAGES:MNONE)
  228. installman        ::
  229.  
  230. #elif defined(INSTALLMAN)
  231. installman        :: .SILENT
  232.     $(UPDATE) -m 444 -l $(INSTALLMANFLAGS) $(MANPAGES) $(INSTALLMAN)
  233. #else
  234. installman        :: .SILENT
  235.     echo "Can't install man page(s): no install directory defined"
  236. #endif
  237.  
  238. lint            :: lintlib
  239. lint            :: MAKESUBDIRS
  240. lintlib            : $(TM).md/lintlib.ln
  241. $(TM).md/lintlib.ln    : .MAKE .SILENT
  242.     $(RM) -f $(.TARGET)
  243.     for i in $(SUBDIRS);
  244.     do
  245. #ifdef TM
  246.         if grep '^MACHINES' $i/Makefile | grep -s $(TM); then
  247.             true;
  248.         else continue;
  249.         fi
  250. #endif TM
  251.         echo %%% ${i} %%%
  252.         (cd $i; $(MAKE) $(PASSVARS) lintlib)
  253.         $(CAT) ${i}/$(TM).md/llib-l${i}.ln >> $(.TARGET)
  254.     done
  255.  
  256. mkmf            ::
  257.     mkmf
  258.  
  259. newtm            ! .MAKE .SILENT
  260.     if $(TEST) -d $(TM).md; then
  261.         true
  262.     else
  263.         mkdir $(TM).md;
  264.         chmod 775 $(TM).md;
  265.         mkmf -m$(TM)
  266.     fi
  267.     for i in $(SUBDIRS);
  268.     do
  269.         echo %%% ${i} %%%
  270.         (cd $i; $(MAKE) $(PASSVARS) newtm)
  271.     done
  272.  
  273. profile            : $(TM).md/$(NAME)$(PROFSUFFIX)
  274. #if empty(TM:Mds3100) && empty(TM:Mds5000)
  275. PROFFLAG = -pg
  276. #else
  277. PROFFLAG = -p
  278. #endif
  279. $(TM).md/$(NAME)$(PROFSUFFIX)    : subdirs_p $(POBJS) $(LIBS:S/.a$/_p.a/g) 
  280.     $(RM) -f $(.TARGET)
  281.     $(CC) $(CFLAGS) $(PROFFLAG) -o $(.TARGET) $(LOADFLAGS) $(POBJS) $(LIBS) 
  282.  
  283.  
  284. #
  285. # The following target does a quick make without cycling through to
  286. # recompile in each of the subdirectories.
  287. #
  288. quick            : $(LIBS) -lc
  289.     $(RM) -f $(TM).md/$(NAME)
  290.     $(CC) $(CFLAGS) -o $(TM).md/$(NAME) $(LOADFLAGS) $(OBJS) $(LIBS)
  291.  
  292. rcsinfo            : .MAKE .SILENT
  293.     for i in $(SUBDIRS);
  294.     do
  295.         echo %%% ${i} %%%
  296.         (cd $i; rcsinfo)
  297.     done
  298.  
  299. #
  300. # The rules immediately below are a trick to get Pmake to remake in
  301. # the subdirectories, but not to consider $(TM).md/$(NAME) to
  302. # be out-of-date with respect to $(OBJS) unless $(OBJS) are actually
  303. # more recent than $(TM).md/$(NAME).
  304. #
  305.  
  306. $(OBJS)            : .DONTCARE
  307. subdirs            : .MAKE .EXEC .SILENT .NOEXPORT
  308.     for i in $(SUBDIRS);
  309.     do
  310. #ifdef TM
  311.         if grep '^MACHINES' $i/Makefile | grep -s $(TM); then
  312.             true;
  313.         else continue;
  314.         fi
  315. #endif TM
  316.         echo %%% ${i} %%%
  317.         (cd $i; $(MAKE) $(PASSVARS))
  318.     done
  319.  
  320. $(POBJS)            : .DONTCARE
  321. subdirs_p            : .MAKE .EXEC .SILENT .NOEXPORT
  322.     for i in $(SUBDIRS);
  323.     do
  324. #ifdef TM
  325.         if grep '^MACHINES' $i/Makefile | grep -s $(TM); then
  326.             true;
  327.         else continue;
  328.         fi
  329. #endif TM
  330.         echo %%% ${i} %%%
  331.         (cd $i; $(MAKE) $(PASSVARS) profile)
  332.     done
  333.  
  334. depend mkmf tags     :: MAKESUBDIRS
  335.  
  336. dist        !
  337. #if defined(DISTDIR) && !empty(DISTDIR)
  338.     for i in Makefile local.mk $(MANPAGES)
  339.     do
  340.     if $(TEST) -e $${i}; then
  341.         $(UPDATE)  $${i} $(DISTDIR)/$${i} ;else true; fi
  342.     done
  343.     for i in $(SUBDIRS)
  344.     do
  345.         echo %%% $${i} %%%
  346. #ifdef TM
  347.         ( cd $${i}; $(MAKE) dist 'DISTDIR=$(DISTDIR)'/$${i} 'TM=$(TM)' )
  348. #else
  349.         ( cd $${i}; $(MAKE) dist 'DISTDIR=$(DISTDIR)'/$${i} )
  350. #endif
  351.     done
  352. #else
  353.     @echo "Sorry, no distribution directory defined for $(NAME)."
  354. #endif
  355.  
  356. #include <all.mk>
  357.  
  358. #endif no_targets
  359.  
  360. .MAKEFLAGS    : -C        # No compatibility needed
  361.